package com.cvs.controller;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.cvs.model.DaysEntity;
import com.cvs.model.EventsEntity;
import com.cvs.model.UserEntity;
import com.cvs.security.SecurityUtilities;
import com.cvs.services.ChmService;

@Controller
public class BookController {

	@Autowired
	private ChmService controllerService;

	public ChmService getControllerService() {
		return controllerService;
	}

	public void setControllerService(ChmService controllerService) {
		this.controllerService = controllerService;
	}

	@RequestMapping(value = "/book", method = RequestMethod.GET)
	public String getBookPage(HttpServletRequest req, ModelMap model,
			HttpSession session, HttpServletResponse resp) throws IOException,
			ParseException {

		UserEntity user = new UserEntity();
		
		SecurityUtilities sec = new SecurityUtilities();

		String username = sec.getLoggedInUserName();
		user = controllerService.searchDatabaseForUsername(username);
		
		List<EventsEntity> events = new ArrayList<EventsEntity>();
		events = controllerService.getEvents();
		
		model.addAttribute("event",events);
		model.addAttribute("user", user);
		return "book";

	}

	@RequestMapping(value = "/calculate", method = RequestMethod.POST)
	public String createNewUser(HttpServletRequest req, ModelMap model,
			HttpSession session, HttpServletResponse resp) throws IOException,
			ParseException {
		
		return "book";
	}
	
}
